

PROP_NAME = document.getElementById("propName");
INVPROP_BT = document.getElementById("btInvProp");
INVPROP_NAME_LABEL = document.getElementById("invPropNameLabel");
INVPROP_NAME = document.getElementById("inversePropName");
SUPER_PROPS = document.getElementById("superProperties");



var userName = "njean@mandriva.com";
// TODO: retrieve the user's name
var PATH_PIMO = "http://www.semanticdesktop.org/ontologies/2007/11/01/pimo#";
var PIMO_DESCRIBINGPROPERTY = PATH_PIMO + "describingProperty";



function page1Show() {
	
	//document.getElementById("Nepomuk-ff-tag").canAdvance="true";
	SUPER_PROPS.builder.refresh();
	PROP_NAME.focus();
	SUPER_PROPS.setAttribute("selectedIndex", 0); // TODO: to be tested, why doesn't it work?
	
}


function genInvPropName() {
	
	var propName = PROP_NAME;
	INVPROP_NAME.value = "inverse of " + propName.value;
	
}


function superPropertiesClick () {
	
	var superPropUri = "";
	if (SUPER_PROPS.selectedIndex != -1) {
		superPropUri = SUPER_PROPS
			.selectedItem.childNodes[1].getAttribute("label");
	}
	
	if (superPropUri == PIMO_DESCRIBINGPROPERTY) {
		INVPROP_BT.setAttribute("hidden", true);
		INVPROP_NAME_LABEL.setAttribute("hidden", true);
		INVPROP_NAME.setAttribute("hidden", true);
	} else {
		INVPROP_BT.setAttribute("hidden", false);
		INVPROP_NAME_LABEL.setAttribute("hidden", false);
		INVPROP_NAME.setAttribute("hidden", false);
	}
	
}


function onFinish() {
	
	var propName = PROP_NAME.value;
	var inversePropName = INVPROP_NAME.value;
	var superPropUri = "";
	if (SUPER_PROPS.selectedIndex != -1) {
		superPropUri = SUPER_PROPS
			.selectedItem.childNodes[1].getAttribute("label");
	}
	
	if (propName == "") {
		alert("Please enter a name for this new property.");
		return;
		// TODO: keep the window open!
	}
	
	//alert(propName);
	
	if ((inversePropName == "") && (superPropUri != PIMO_DESCRIBINGPROPERTY)) {
		alert("Please enter a name for the inverse of this new property.");
		return;
		// TODO: keep the window open!
	}
	
	//alert(inversePropName);
	
	if (superPropUri == "") {
		alert("You must a select a super property from the list.");
		return;
		// TODO: keep the window open!
	}
	
	//alert(superPropUri);
	
	if (superPropUri == PIMO_DESCRIBINGPROPERTY) {
		// Register this new property as a describing property. ("object-to-value")
		
		run(true, ["createDescribingProperty", userName, propName]);
		
	} else {
		// Register this new property as an "object-to-object" property.
		
		run(true, ["createProperty", userName, propName, superPropUri, inversePropName]);
		
	}
	
	var res = success(null, "");
	if (res != null) {
		
		alert("The property has properly been created!");
		
	} else {
		
		// TODO
		
	}
	
}



